// Achievement by G3X / GeXeH - Enjoy
// Version 1.0

// Achievement: Swim underwater for 5 minutes.

local Value = achievements.GetValue( "Master Swimmer", "total", 0 )

local function Update()

	if (Value != 300) then
		// print("Check Started.\n")
		local ply = LocalPlayer()

		if (!ValidEntity( ply )) then return end
		
		if ( (ply:WaterLevel() == 3) && (!ply:IsOnGround()) && (ply:GetMoveType() == MOVETYPE_WALK) && (!ply:InVehicle()) ) then
			// print("Player Inside Water.\n")
			Value = math.Clamp( Value + 1, 0, 300 )
			achievements.SetValue( "Master Swimmer", "total", Value )
			achievements.Update( "Master Swimmer", Value / 300, string.FormattedTime( Value, "%02i:%02i" ) )
			// achievements.Update( "Master Swimmer", Value / 300, Value .. "/300" )
		else
			// print("Player Outside Water.\n")
		end

		// print("Check Ended.\n")
	
	else
		timer.Destroy("Achievement.MasterSwimmer")
	end

end

timer.Create("Achievement.MasterSwimmer", 1, 0, Update)

achievements.Register( "Master Swimmer", "Swim underwater for 5 minutes.", "achievements/masterswimmer", Value / 300, string.FormattedTime( Value, "%02i:%02i" ) )